package com.example.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.bson.types.ObjectId;

import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Field;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Index;
import dev.morphia.annotations.IndexOptions;
import dev.morphia.annotations.Indexes;
import dev.morphia.annotations.Reference;
import lombok.Data;

@Entity("book")
@Indexes(
        @Index(fields = @Field("title"), options = @IndexOptions(unique = true))
)
@Data
public class Book implements Serializable{
 
    private static final long serialVersionUID = -4770189354904113228L;

	@Id
    private ObjectId id;
 
    private String title;
 
    private List<String> tags;
 
    private String description;
 
    private Date publishDate;
 
    //idOnly设置为true,该列在DB中只存ID，以便关联查询
    @Reference(idOnly = true)
    private Author author;
}